package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.PageSelect;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/*
    员工管理Controller
* */
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpService empService;

    /*
    * 员工列表查询
    * */
//    @GetMapping
//    public Result list(){
//        log.info("员工列表查询");
//        List<Emp> list = empService.list();
//        return Result.success(list);
//    }
    /*
    * 分页查询员工列表信息
    * */
    /**
     * @description:
     * @param: 
     * @param page
     * @param pageSize
     * @param name
     * @param gender
     * @param begin
     * @param end
     * @return: com.itheima.pojo.Result
     **/

    @GetMapping
    public Result getByPageList(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                String name, Short gender,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("分页查询，参数{}，{}，{}，{}，{}，{}",page,pageSize,name,gender,begin,end);
        //调用Service进行分页查询
        PageBean list = empService.listByPage(page,pageSize,name,gender,begin,end);
        return Result.success(list);
    }

    /*
    * 批量删除员工的数据信息
    * */

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除员工的数据信息{}",ids);
        empService.delete(ids);
        return Result.success();
    }

    /*
    * 添加员工信息
    * */
    @PostMapping
    public Result insert(@RequestBody Emp emp){
        log.info("添加员工信息{}",emp);
        empService.insert(emp);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工的数据信息，{}",emp);
        empService.update(emp);
        return Result.success();
    }



}
